import { defineConfig } from 'vite'
import path from "path"
import vue from '@vitejs/plugin-vue'
import viteCompression from 'vite-plugin-compression'
import progress from 'vite-plugin-progress'

export default defineConfig({
	resolve: {
		alias: {
			"@": path.resolve(__dirname, "src"),
		}
	},
	server: {
		// host: '10.40.126.106',
		host: '::',
		port: 10000,
		proxy: {
			// '/api': 'http://119.3.107.118:31314',
			'/develop': {
				target: 'http://192.168.10.174:31314', // 开发环境
				changeOrigin: true,
				rewrite: (path) => path.replace('/develop/api', '/api'),
			},
			'/release': {
				target: 'http://122.9.86.249:32046',
				changeOrigin: true,
				rewrite: (path) => path.replace('/release/api', '/api'),
			},
		},
	},
	plugins: [
		progress({
			format: 'building [:bar] :percent',
			total: 100,
			width: 30,
		}),
		vue(),
		// gzip压缩 生产环境生成 .gz 文件
		viteCompression({
			verbose: true,
			disable: false,
			threshold: 10240,
			algorithm: 'gzip',
			ext: '.gz',
		}),
	],
	css: {
		//css预处理
		preprocessorOptions: {
			scss: {
				/*
				引入var.scss全局预定义变量，
				如果引入多个文件，
				可以使用
				'@import "@/assets/scss/globalVariable1.scss";@import "@/assets/scss/globalVariable2.scss";'
				这种格式
				 */
				// additionalData: '@import "@/assets/scss/globalVariable.scss";'
			}
		}
	},
  build:{
    rollupOptions: {
      // https://rollupjs.org/guide/en/#outputmanualchunks
      output: {
        manualChunks: {
			// 分割代码到指定文件
			'page2': [
				'./src/views/Page1.vue',
				'./src/views/Page3.vue',
				'./src/views/Page2.vue',
				'./src/views/Page2Detail.vue',
				'./src/views/Page2Index.vue',
				// './src/UserDashboard',
				// './src/UserProfileEdit',
			],
        },
      },
    }
  }
})
